const http = require('http');
const https = require('https');
// const fs = require('fs');

const express = require('express')
const app = express()
const port = 3000
app.use(express.static('www'))


app.get('/wx/login', (req, res) => {
  console.log(req.header)
    let code = req.query.code
    let appid = 'wx6d47c603af6377f1'
    let secret = 'ac667e21450577b8844284d4e2e8e817'
    https.get('https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${code}&grant_type=authorization_code', (ret) => {
      ret.on('data', (d) => {
        // console.error(d.toString());
        res.end(d.toString())
        }
    );

    }).on('error', (e) => {
        console.error(e);
        // res.sendStatus(404);
        res.send({errorMsg:'错误体现'})
        }
    );
  // res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})
